package cat.joronya.supermanager;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import cat.joronya.supermanager.drawer.DrawerActivity;
import cat.joronya.supermanager.drawer.DrawerItem;
import cat.joronya.supermanager.home.HomeFragment;
import cat.joronya.supermanager.market.MarketListActivity;
import cat.joronya.supermanager.privateleague.PrivateLeagueListActivity;
import cat.joronya.supermanager.team.MyTeamsListActivity;

public class SupermanagerActivity extends DrawerActivity 
{
	public static final String TAG = "Supervermut";
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
    	// set layout and call super onCreate
    	setmLayoutResource(R.layout.home_drawer_layout);
    	super.onCreate(savedInstanceState);
    	
    	// setejem el fragment q toca
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction()
                       .replace(R.id.fragment, new HomeFragment())
                       .commit();
        
        // titol de la pantalla home inicalment
        setTitle(getResources().getString(R.string.home_tab));
    } 
    
    @Override
    public void onConfigurationChanged(Configuration newConfig) 
    {
    	Log.d(TAG,"SupermanagerActivity.onConfigurationChanged called");
		
		// actualitzem dades
    	super.onConfigurationChanged(newConfig);
    }
    
    protected DrawerItem[] getDrawerItems()
    {
    	mDrawerTitles = getResources().getStringArray(R.array.drawer_titles);
        mDrawerIcons = getResources().getStringArray(R.array.drawer_icons);
        
    	DrawerItem[] items = new DrawerItem[mDrawerTitles.length];
    	for(int i=0; i<mDrawerTitles.length; i++)
    	{
    		int icon = getResources().getIdentifier(mDrawerIcons[i], "drawable", this.getPackageName());
    		items[i] = DrawerItem.create(mDrawerTitles[i], icon);
    	}
    	
    	return items;
    }
        
    /** 
     * Swaps fragments in the main content view 
     */
    protected void selectItem(int position) 
    {
    	setTitle(mDrawerTitles[position]);
    	Log.d(TAG,"selectItem on drawer");
    	
    	switch(position) 
    	{
			case 0:
				
				break;
			case 1:
				// private league list activity
				Intent privateLeagueListActivity = new Intent(getBaseContext(), PrivateLeagueListActivity.class);
        		startActivity(privateLeagueListActivity);
        		overridePendingTransition(0,0);
				break;
			case 2:
				// market list activity
				Intent marketListActivity = new Intent(getBaseContext(), MarketListActivity.class);
        		startActivity(marketListActivity);
        		overridePendingTransition(0,0);
        		break;
			case 3:
				// my teams list activity
				Intent myteamsListActivity = new Intent(getBaseContext(), MyTeamsListActivity.class);
				startActivity(myteamsListActivity);
				overridePendingTransition(0,0);
				break;
			default:
				
				break;
		}
    	
    	mDrawerLayout.closeDrawer(mDrawerList);
    }
}
